//  ========== 
//  = Loading_lh = 
//  ========== 
/*
 * 创建对象			var load1 = Loading_lh.createNew();
 * 添加已有svg的id 	load1.svgid("svgid");
 * 加载				load1.Load_lh();
 * 错误				load1.Error_lh();
 * 结束				load1.End_loading();
 * 
 * 未来：
 * 		可选加载样式;
 * */
! function() {
	var Loading_lh = {};
//	Loading_lh.createNew = FCreateNew;
	
	//定义设置CreateNew方法
	Object.defineProperty(Loading_lh, "CreateNew", {
	    value: function () {	        
	     return FCreateNew(); 
	    }
	    });
	FCreateNew = function () {
		var loading_lh = Object.create(Object);
		loading_lh._switch = false;
		                
		    	//定义设置_svgid属性的方法
		Object.defineProperty(loading_lh, "Svgid", {
			value: function(v) {
				this._svgid = v;
				return this;
			}
		});
		
		Object.defineProperty(loading_lh, "Load_lh", {
			value: function() {
				loading_lh._switch ? console.log("zhe") : DetermineProperties(this); //属性自检
				console.log(this);
				 Create_g_Loading_lh(loading_lh);
				this.loading_g.style("opacity", 0.8);
				//			this.loading_rect.style("opacity", 0.8);
				this.loading_text.text("loading");
				return this;
			}
		});
		
		    Object.defineProperty(loading_lh, "Error_lh", {
		    value: function() {
		    	this.loading_g.style("opacity", 0.8)
				//			this.loading_rect.style("opacity", 0.8);
			this.loading_text.text("error");
		        return this;
		        }
		    });
	
	    Object.defineProperty(loading_lh, "End_Loading", {
	    value: function() {
//	    	this.loading_g.style("opacity", 0);
			this.loading_g.remove();
	        return this;
	        }
	    });
	        
			//  ========== 
			//  = 判断属性 = 
			//  ========== 
		Detect_function = function(object_lh) {
			return typeof(object_lh) == "undefined";
		}

		DetermineProperties = function(loading_lh) {

			Detect_function(loading_lh._svgid) ?
				console.log("请添加svgid用于添加g") :
				d3.select("#" + loading_lh._svgid)[0][0] == null ?
				console.log("请检查id是否正确") :
				SetId(loading_lh);
			loading_lh._width = $("#" + loading_lh._svgid).width();
			loading_lh._height = $("#" + loading_lh._svgid).height();
			//			loading_lh._width = ceshiwidth(d3.select("#" + loading_lh._svgid)[0][0]);
			//			loading_lh._width = document.getElementById(loading_lh._svgid).offsetWidth;

			//			loading_lh._height = ceshiheight(d3.select("#"+loading_lh._svgid)[0][0]);
			console.log(loading_lh._width, loading_lh._height);
			loading_lh._ox = loading_lh._width / 2;
			loading_lh._oy = loading_lh._height / 2;
			console.log(d3.select("#" + loading_lh._loading_lh_rect_id));
			
			loading_lh._switch = true;
			console.log(loading_lh._switch);
			ceshiwidth = function(w) {
				var v = 0,
					d = document,
					w = window;
				if((!d.compatMode || d.compatMode == 'CSS1Compat') && !w.opera && d.documentElement && d.documentElement.clientWidth) {
					v = d.documentElement.clientWidth;
				} else if(d.body && d.body.clientWidth) {
					v = d.body.clientWidth;
				} else if(xDef(w.innerWidth, w.innerHeight, d.height)) {
					v = w.innerWidth;
					if(d.height > w.innerHeight) v -= 16;
				}
				return v;
			}

		}

		Create_g_Loading_lh = function(loading_lh) {
			console.log(loading_lh);
			loading_lh.loading_g = d3.select("#" + loading_lh._svgid)
				.append("g")
				.attr("id", loading_lh._loading_lh_g_id)
				.attr("width", loading_lh._width)
				.attr("height", loading_lh._height)
				.style("opacity", 0);
			//				loading_lh.loading_g.hide();
			//								.attr("hidden",true);
			loading_lh.loading_rect = loading_lh.loading_g.append("rect")
				.attr("fill", "white")
				//				.style("opacity", 0)
				.attr("id", loading_lh._loading_lh_rect_id)
				.attr("width", loading_lh._width)
				.attr("height", loading_lh._height);

			loading_lh.loading_text = loading_lh.loading_g.append("text")
				.attr("dy", loading_lh._oy)
				.attr("dx", loading_lh._ox);
		}

		Tool_Loading_lh = function(loading_lh) {

		}

		SetId = function(loading_lh) {
				loading_lh._loading_lh_g_id = loading_lh._svgid + "Loading_lh_g";
				loading_lh._loading_lh_rect_id = loading_lh._svgid + "Loading_lh_rect";
				loading_lh._loading_lh_text_id = loading_lh._svgid + "Loading_lh_text";
			}
			//		window.onresize = function(event) {
			//			update();
			//		};
			//		function updata () {
			//		    loading_lh._svg.attr({
			//		    	"width":
			//		    })
			//		}
		return loading_lh;
	};
	this.Loading_lh = Loading_lh;
}();